package com.moon.back.config;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class Field {
    private String name;
    private FieldType type;
    private boolean sortable;
    private boolean noindex;

    public enum FieldType {
        TEXT,
        NUMERIC,
        TAG
    }

    public static FieldBuilder text(String name) {
        return Field.builder()
                .name(name)
                .type(FieldType.TEXT);
    }

    public static FieldBuilder numeric(String name) {
        return Field.builder()
                .name(name)
                .type(FieldType.NUMERIC);
    }

    public static FieldBuilder tag(String name) {
        return Field.builder()
                .name(name)
                .type(FieldType.TAG);
    }

    public String toRedisCommand() {
        StringBuilder command = new StringBuilder();
        command.append(name).append(" ");
        
        switch (type) {
            case TEXT:
                command.append("TEXT");
                break;
            case NUMERIC:
                command.append("NUMERIC");
                break;
            case TAG:
                command.append("TAG");
                break;
        }
        
        if (sortable) {
            command.append(" SORTABLE");
        }
        if (noindex) {
            command.append(" NOINDEX");
        }
        
        return command.toString();
    }
}